<?php

//服务器和数据库信息
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "myDB";
 
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbName);
 
// 检测连接
if ($conn->connect_error) {
  die("连接失败: " . $conn->connect_error);
}

// 表头数据
$id = 'id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY';
$firstName = 'firstname VARCHAR(30) NOT NULL';
$lastName = 'lastname VARCHAR(30) NOT NULL';
$email = 'email VARCHAR(50)';
$regdate = 'reg_date TIMESTAMP';
$tableHead = array();
array_push($tableHead, $id, $firstName, $lastName, $email, $regdate);

//将表头数据转换成字符串
$tableHead = implode(",", $tableHead);

//表名
$tableName = 'MyGuest';

//创建表
$sql = "CREATE TABLE $tableName ( $tableHead )";
if ($conn->query($sql) === true) {

  echo ("Table $tableName created successfully");
} else {
  echo ("fail to creat Table $tableName" . PHP_EOL . $conn->error);
}
$conn->close();
?>